<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/2
 * Time: 15:41
 */

namespace app\flower\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class AdminLogoController extends AdminBaseController
{
    public function index(){
        $result = Db::name('flower_logos')->where('id',1)->find();
        if(empty($result)){
            $this->assign('images',array('id'=>'','logo'=>'','guestshuo'=>''));
            $this->assign('logo','__TMPL__/public/assets/images/default-thumbnail.png');
            $this->assign('guestshuo','__TMPL__/public/assets/images/default-thumbnail.png');
        }else{
            $logo = 'http://'.$_SERVER['HTTP_HOST'].'/upload/'.$result['logo'];
            $guestshuo = 'http://'.$_SERVER['HTTP_HOST'].'/upload/'.$result['guestshuo'];
            $this->assign('images',$result);
            $this->assign('logo',$logo);
            $this->assign('guestshuo',$guestshuo);
        }
        return $this->fetch('index');
    }
    public function add(){
        $id =input('id');
        $logo = input('logo.thumbnail');
        $guestshuo = input('guestshuo.thumbnail');
        $datas['logo'] = $logo;
        $datas['guestshuo'] = $guestshuo;
        if(empty($id)){
            $result = Db::name('flower_logos')->insert($datas);
        }else{
            $result = Db::name('flower_logos')->where('id',$id)->update($datas);
        }
        if($result>0){
            $this->success('提交成功');
        }else{
            $this->success('提交失败');
        }
    }
}